<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<meta name="keyword" content="">

    <link rel="shortcut icon" href="/node-mongodb-native/3.1/img/favicon.png">

    <title>Topology Monitoring</title>

    <link rel="stylesheet" href="/node-mongodb-native/3.1/lib/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/3.1/lib/font-awesome/css/font-awesome.min.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/3.1/css/mongodb-docs.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/3.1/css/overrides.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/3.1/lib/highlight/styles/idea.css" />
<link rel="stylesheet" href="/node-mongodb-native/3.1/lib/bootstrap-toggle/bootstrap-toggle.min.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/3.1/css/java.css" type="text/css" />


  </head>

  <body>
  
  <section id="container" class="">
      
      <header id="header-db" class="row" role="navigation">
  <div class="header-content">
    <div class="toggle-nav pull-left">
        <i class="fa fa-bars"></i>
        <div class="icon-reorder tooltips" data-original-title="Toggle Navigation" data-placement="bottom"></div>
    </div>
    
    <div class="logo pull-left">
      <a href="https://www.mongodb.com/">
        <img src="https://mongodb.github.io/node-mongodb-native/img/logo-mongodb-header.png", alt="MongoDB.com" />
      </a>
    </div>
    
    <div>
<div class="nav-items pull-right">
  <a href="https://university.mongodb.com" data-toggle="tooltip" data-placement="bottom" title="Free Online Classes">MongoDB University</a>
  <a href="https://www.mongodb.com/try" data-toggle="tooltip" data-placement="bottom" title="Download MongoDB">Downloads</a>
  <a href="https://www.mongodb.com/community" data-toggle="tooltip" data-placement="bottom" title="Get involved with MongoDB">Community</a>
  <a href="https://www.mongodb.com/docs" data-toggle="tooltip" data-placement="bottom" title="The MongoDB Documentation">Docs</a>
  <a href="https://www.mongodb.com/blog" data-toggle="tooltip" data-placement="bottom" title="The MongoDB Blog">Blog</a>
  <div id="search">
<form method="get" action="//www.google.com/search" target="_blank">
    <input type="text" name="searchQuery" size="20" value="" autocomplete="off" placeholder="Search docs">
    <input type="hidden" name="site" value="/node-mongodb-native/3.1">
    <input type="hidden" name="q" value="">
    <label for="searchQuery"><i class="fa fa-search fa-1"></i></label>
</form>
</div>

</div>
</div>

  </div>
</header>


      

      
<aside id="sidebar" class="sidebar">
    <div class="ssidebar nav-collapse">
      <div class="ssidebarwrapper">
        <h3>
          <a class="index-link" href="/node-mongodb-native/3.1/../">MongoDB Node.js Driver</a>
          <a class="version pull-right" href="/node-mongodb-native/3.1">3.1</a>
        </h3>

        
        <ul class="sidebar-menu">
          
          
          
          
          
          
          
          
          
          
          
          

          
          
            
            









  


          
            
            









  


          
            
            









  
    
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
    
      
    
  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
    
      
    
  


        
          
        
      
    
    
      
    
  


          
            
            









  
    
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
    
      
    
  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
    
      
    
  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  
  
  
  
  
  
  
  

  
    
    
    
      
      
      
        
      
    
    
  
  


        
      
    
    
  


        
      
    
      
      
        
      
    
      
      
    
    
  


          
            
            









  
    
    
      
      
    
    
  


          
            
            









  


          
            
            









  


          
            
            









  


          
            
            









  


          

          

          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/3.1/installation-guide/installation-guide/">
        <i class='fa fa-puzzle-piece'></i>
        Installation Guide
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/3.1/quick-start/quick-start/">
        <i class='fa fa-road'></i>
        Quick Start
    </a>
  </li>


          
            
            
















<li class="toctree-l1 ">
  <a href="/node-mongodb-native/3.1/tutorials/main/" class="">
      <i class='fa fa-thumb-tack'></i>
      <span>Tutorials</span>
      <span class="menu-arrow fa fa-angle-right"></span>
  </a>
    <ul >
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/3.1/tutorials/connect/" class="">
      <i class='fa'></i>
      <span>Connect to MongoDB</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/tutorials/connect/authenticating/">
        <i class='fa'></i>
        Authentication
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/tutorials/connect/ssl/">
        <i class='fa'></i>
        SSL Settings
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/collations/">
        <i class='fa'></i>
        Collations
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/collections/">
        <i class='fa'></i>
        Collections
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/create-indexes/">
        <i class='fa'></i>
        Create Indexes
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/crud/">
        <i class='fa'></i>
        CRUD Operations
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/projections/">
        <i class='fa'></i>
        Projections
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/aggregation/">
        <i class='fa'></i>
        Aggregation
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/text-search/">
        <i class='fa'></i>
        Text Search
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/geospatial-search/">
        <i class='fa'></i>
        Geospatial Search
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/tutorials/commands/">
        <i class='fa'></i>
        Database Commands
    </a>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/3.1/tutorials/gridfs/" class="">
      <i class='fa'></i>
      <span>GridFS</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/tutorials/gridfs/streaming/">
        <i class='fa'></i>
        GridFS API
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/tutorials/gridfs/gridstore/">
        <i class='fa'></i>
        Legacy GridStore
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
    </ul>
  </li>


          
            
            













  




<li class="toctree-l1  current">
  <a href="/node-mongodb-native/3.1/reference/main/" class="">
      <i class='fa fa-book'></i>
      <span>Reference</span>
      <span class="menu-arrow fa fa-angle-down"></span>
  </a>
    <ul  class="current">
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/3.1/reference/connecting/" class="">
      <i class='fa'></i>
      <span>Connection Options</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/reference/connecting/connection-settings/">
        <i class='fa'></i>
        Connection Settings
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/3.1/reference/ecmascriptnext/" class="">
      <i class='fa'></i>
      <span>ECMAScript Next</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/reference/ecmascriptnext/connecting/">
        <i class='fa'></i>
        Connecting
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/reference/ecmascriptnext/crud/">
        <i class='fa'></i>
        CRUD Operations
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        













  




<li class="toctree-l2  current">
  <a href="/node-mongodb-native/3.1/reference/management/" class="">
      <i class='fa'></i>
      <span>Management</span>
      
  </a>
    <ul  class="current">
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/reference/management/logging/">
        <i class='fa'></i>
        Logging
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/reference/management/apm/">
        <i class='fa'></i>
        APM
    </a>
  </li>


        
        
        
        
        













  




    <li class="toctree-l3">
    <a href="/node-mongodb-native/3.1/reference/management/sdam-monitoring/">
        <i class='fa'></i>
        Topology Monitoring
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/reference/pool/">
        <i class='fa'></i>
        Pool Design
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/reference/faq/">
        <i class='fa'></i>
        Frequently Asked Questions
    </a>
  </li>


        
        
    </ul>
  </li>


          
            
            
















<li class="toctree-l1 ">
  <a href="/node-mongodb-native/3.1/upgrade-migration/main/" class="">
      <i class='fa fa-cog'></i>
      <span>Upgrade Guide</span>
      <span class="menu-arrow fa fa-angle-right"></span>
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/3.1/upgrade-migration/upgrading/">
        <i class='fa fa-wrench'></i>
        Upgrading to 2.x
    </a>
  </li>


        
        
    </ul>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/3.1/api">
        <i class='fa fa-file-text-o'></i>
        API Documentation
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="https://github.com/mongodb/node-mongodb-native">
        <i class='fa fa-github'></i>
        Source Code
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/3.1/issues-help/">
        <i class='fa fa-life-ring'></i>
        Issues &amp; Help
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="https://gitter.im/mongodb/node-mongodb-native?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge">
        <img src='https://badges.gitter.im/Join Chat.svg'/>
        
    </a>
  </li>


          
        </ul>
        
    </div>
  </div>
  
</aside>

<div class="option-popup closed hidden" id="optionsVersionsPopup">
<div class="option-header">
  <i class="fa fa-gear"></i>
  <span>OPTIONS</span>
  <i class="fa fa-angle-up pull-right"></i>
</div>
<div class="option-body">
  <ul>
      
      <li>
        <label>Version</label>
        <div class="btn-group btn-group-xs pull-right">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            Select Version <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu" id="optionsVersionsMenu">
          </ul>
        </div>
      </li>

   


    

  </ul>
</div>
</div>



      
      <section id="main-content" class="content">
          <section class="main-column pull-left">
            <div class="document">
              <div class="documentwrapper">
                <div class="bodywrapper">
                  <div class="body">

                    <div class="alert alert-info" role="alert">
  Note: You are currently viewing version 3.1 of the Node.js driver documentation.
  <a href="https://www.mongodb.com/docs/drivers/node">Click here</a> for the latest version.
</div>



   
<a class="edit-link" href="https://github.com/mongodb/node-mongodb-native/blob/3.1/docs/reference/content/reference/management/sdam-monitoring.md" target="_blank" title="Edit reference/management/sdam-monitoring.md on GitHub"><i class="fa fa-pencil-square-o"></i></a>










<div class="bc">
<ul>
  
  
  
  
  <li><a href="/node-mongodb-native/3.1/reference/main/">Reference</a> <i class="fa fa-angle-right"></i></li>
  <li><a href="/node-mongodb-native/3.1/reference/management/">Management</a> <i class="fa fa-angle-right"></i></li>
  <li>Topology Monitoring</li>
</ul>
</div>




<h1 id="topology-management">Topology Management</h1>

<p>The Node.js driver <code>2.1.10</code> or higher features SDAM Monitoring events,
allowing an application or tool to monitor changes in the drivers
view of a single server, replica set or <code>mongos</code>. This allows an
application to react to changes of topology, such as a secondary
joining or leaving a replica set.</p>

<h2 id="overview-of-sdam-events">Overview of SDAM events</h2>

<table>
<thead>
<tr>
<th align="left">Event</th>
<th align="left">Applies To</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left">serverOpening</td>
<td align="left">Server, Replicaset, Mongos</td>
<td align="left">Emitted when server connection is established.</td>
</tr>

<tr>
<td align="left">serverClosed</td>
<td align="left">Server, Replicaset, Mongos</td>
<td align="left">Emitted when server connection gets closed.</td>
</tr>

<tr>
<td align="left">serverDescriptionChanged</td>
<td align="left">Server, Replicaset, Mongos</td>
<td align="left">Emitted when server state changes (such as from secondary to primary).</td>
</tr>

<tr>
<td align="left">topologyOpening</td>
<td align="left">Server, Replicaset, Mongos</td>
<td align="left">Emitted before any server connections are performed.</td>
</tr>

<tr>
<td align="left">topologyClosed</td>
<td align="left">Server, Replicaset, Mongos</td>
<td align="left">Emitted when topology connections have all closed.</td>
</tr>

<tr>
<td align="left">topologyDescriptionChanged</td>
<td align="left">Replicaset, Mongos</td>
<td align="left">Emitted when the topology shape changes, such as a new primary being elected or a mongos proxy disconnecting.</td>
</tr>

<tr>
<td align="left">serverHeartbeatStarted</td>
<td align="left">Replicaset, Mongos</td>
<td align="left">Emitted before the ismaster command is issued to a MongoDB server.</td>
</tr>

<tr>
<td align="left">serverHeartbeatSucceeded</td>
<td align="left">Replicaset, Mongos</td>
<td align="left">Emitted after a successful ismaster command was issued to a MongoDB server.</td>
</tr>

<tr>
<td align="left">serverHeartbeatFailed</td>
<td align="left">Replicaset, Mongos</td>
<td align="left">Emitted if a ismaster command failed against a specific MongoDB server.</td>
</tr>
</tbody>
</table>

<h2 id="simple-code-example">Simple Code Example</h2>

<p>The following example demonstrates how to connect to a replica set and monitor all the events that are emitted by the replica set topology.</p>

<pre><code class="language-js">const MongoClient = require('mongodb').MongoClient;

const url = 'mongodb://localhost:31000,localhost:31001/?replicaSet=rs';
const client = new MongoClient();

client.on('serverDescriptionChanged', function(event) {
  console.log('received serverDescriptionChanged');
  console.log(JSON.stringify(event, null, 2));
});

client.on('serverHeartbeatStarted', function(event) {
  console.log('received serverHeartbeatStarted');
  console.log(JSON.stringify(event, null, 2));
});

client.on('serverHeartbeatSucceeded', function(event) {
  console.log('received serverHeartbeatSucceeded');
  console.log(JSON.stringify(event, null, 2));
});

client.on('serverHeartbeatFailed', function(event) {
  console.log('received serverHeartbeatFailed');
  console.log(JSON.stringify(event, null, 2));
});

client.on('serverOpening', function(event) {
  console.log('received serverOpening');
  console.log(JSON.stringify(event, null, 2));
});

client.on('serverClosed', function(event) {
  console.log('received serverClosed');
  console.log(JSON.stringify(event, null, 2));
});

client.on('topologyOpening', function(event) {
  console.log('received topologyOpening');
  console.log(JSON.stringify(event, null, 2));
});

client.on('topologyClosed', function(event) {
  console.log('received topologyClosed');
  console.log(JSON.stringify(event, null, 2));
});

client.on('topologyDescriptionChanged', function(event) {
  console.log('received topologyDescriptionChanged');
  console.log(JSON.stringify(event, null, 2));
});

client.connect(function(err, client) {
  if(err) throw err;
});
</code></pre>

<h2 id="example-documents-returned-for-each-event-type">Example Documents Returned For Each Event Type</h2>

<p>The following examples serve as a guide to the format of the returned documents.</p>

<h3 id="serverdescriptionchanged">serverDescriptionChanged</h3>

<pre><code class="language-js">{ address: 'localhost:27017',
  arbiters: [],
  hosts: [],
  passives: [],
  type: 'RSPrimary' }
</code></pre>

<p>The type can be one of the following values.</p>

<table>
<thead>
<tr>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left">RSPrimary</td>
<td align="left">Primary server</td>
</tr>

<tr>
<td align="left">RSSecondary</td>
<td align="left">Secondary server</td>
</tr>

<tr>
<td align="left">RSArbiter</td>
<td align="left">Arbiter</td>
</tr>

<tr>
<td align="left">Standalone</td>
<td align="left">Standalone server</td>
</tr>

<tr>
<td align="left">Unknown</td>
<td align="left">Unknown server</td>
</tr>

<tr>
<td align="left">Mongos</td>
<td align="left">Mongos proxy</td>
</tr>
</tbody>
</table>

<h3 id="serverheartbeatstarted">serverHeartbeatStarted</h3>

<pre><code class="language-js">{ connectionId: 'localhost:27017' }
</code></pre>

<h3 id="serverheartbeatsucceeded">serverHeartbeatSucceeded</h3>

<pre><code class="language-js">{ durationMS: 20,
  reply: {
    setName: &quot;rs&quot;, setVersion: 1, electionId: new ObjectId(),
    maxBsonObjectSize : 16777216, maxMessageSizeBytes : 48000000,
    maxWriteBatchSize : 1000, localTime : new Date(),
    maxWireVersion : 4, minWireVersion : 0, ok : 1,
    hosts: [&quot;localhost:32000&quot;, &quot;localhost:32001&quot;],
    arbiters: [&quot;localhost:32002&quot;]
  },
  connectionId: 'localhost:27017' }
</code></pre>

<h3 id="serverheartbeatfailed">serverHeartbeatFailed</h3>

<pre><code class="language-js">{ durationMS: 20,
  err: new MongoError('some error'),
  connectionId: 'localhost:27017' }
</code></pre>

<h3 id="serveropening">serverOpening</h3>

<pre><code class="language-js">{ topologyId: 0, name: 'localhost:27017' }
</code></pre>

<h3 id="serverclosed">serverClosed</h3>

<pre><code class="language-js">{ topologyId: 0, name: 'localhost:27017' }
</code></pre>

<h3 id="topologyopening">topologyOpening</h3>

<pre><code class="language-js">{ topologyId: 0 }
</code></pre>

<h3 id="topologyclosed">topologyClosed</h3>

<pre><code class="language-js">{ topologyId: 0 }
</code></pre>

<h3 id="topologydescriptionchanged">topologyDescriptionChanged</h3>

<pre><code class="language-js">{
  topologyId: 0,
  previousDescription: {
    topologyType: &quot;ReplicaSetNoPrimary&quot;,
    setName: &quot;rs&quot;,
    servers: [
      {
        type: &quot;RSSecondary&quot;,
        address: &quot;localhost:32001&quot;,
        hosts: [
          &quot;localhost:32000&quot;,
          &quot;localhost:32001&quot;
        ],
        arbiters: [
          &quot;localhost:32002&quot;
        ],
        setName: &quot;rs&quot;
      },
      {
        type: &quot;RSSecondary&quot;,
        address: &quot;localhost:32000&quot;,
        hosts: [
          &quot;localhost:32000&quot;,
          &quot;localhost:32001&quot;
        ],
        arbiters: [
          &quot;localhost:32002&quot;
        ],
        setName: &quot;rs&quot;
      },
      {
        type: &quot;RSArbiter&quot;,
        address: &quot;localhost:32002&quot;,
        hosts: [
          &quot;localhost:32000&quot;,
          &quot;localhost:32001&quot;
        ],
        arbiters: [
          &quot;localhost:32002&quot;
        ],
        setName: &quot;rs&quot;
      }
    ]
  },
  newDescription: {
    topologyType: &quot;ReplicaSetWithPrimary&quot;,
    setName: &quot;rs&quot;,
    servers: [
      {
        type: &quot;RSPrimary&quot;,
        address: &quot;localhost:32001&quot;,
        hosts: [
          &quot;localhost:32000&quot;,
          &quot;localhost:32001&quot;
        ],
        arbiters: [
          &quot;localhost:32002&quot;
        ],
        setName: &quot;rs&quot;
      },
      {
        type: &quot;RSSecondary&quot;,
        address: &quot;localhost:32000&quot;,
        hosts: [
          &quot;localhost:32000&quot;,
          &quot;localhost:32001&quot;
        ],
        arbiters: [
          &quot;localhost:32002&quot;
        ],
        setName: &quot;rs&quot;
      },
      {
        type: &quot;RSArbiter&quot;,
        address: &quot;localhost:32002&quot;,
        hosts: [
          &quot;localhost:32000&quot;,
          &quot;localhost:32001&quot;
        ],
        arbiters: [
          &quot;localhost:32002&quot;
        ],
        setName: &quot;rs&quot;
      }
    ]
  },
  diff: {
    servers: [{
        &quot;address&quot;: &quot;localhost:32000&quot;,
        &quot;from&quot;: &quot;RSSecondary&quot;,
        &quot;to&quot;: &quot;RSPrimary&quot;
      }
    ]
  }  
}
</code></pre>

<p>The <code>type</code> field in the server array documents can be one of the following values:</p>

<table>
<thead>
<tr>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left">RSPrimary</td>
<td align="left">Primary server</td>
</tr>

<tr>
<td align="left">RSSecondary</td>
<td align="left">Secondary server</td>
</tr>

<tr>
<td align="left">RSArbiter</td>
<td align="left">Arbiter</td>
</tr>

<tr>
<td align="left">Standalone</td>
<td align="left">Standalone server</td>
</tr>

<tr>
<td align="left">Unknown</td>
<td align="left">Unknown server</td>
</tr>
</tbody>
</table>

<p>The <code>topologyType</code> field can be one of the following values:</p>

<table>
<thead>
<tr>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left">ReplicaSetWithPrimary</td>
<td align="left">Replica set with a primary</td>
</tr>

<tr>
<td align="left">ReplicaSetNoPrimary</td>
<td align="left">Replica set with no primary</td>
</tr>

<tr>
<td align="left">Unknown</td>
<td align="left">Unknown topology</td>
</tr>
</tbody>
</table>






<div id="btnv">
  
  <div class="pull-left">
  <a class="navigation prev" href="/node-mongodb-native/3.1/reference/management/apm/">
      <i class="fa fa-long-arrow-left"> </i> APM
  </a>
  </div>
  
  
  <div class="pull-right">
  <a class="navigation next" href="/node-mongodb-native/3.1/reference/pool/">
    Pool Design <i class="fa fa-long-arrow-right"> </i>
  </a>
  
</div>
</div>


</div>
<div class="right-column">
<div class="wrapper">
  
  <div class="toc">
    <span class="toc-header">On this page</span>
    <nav id="TableOfContents">
<ul>
<li><a href="#topology-management">Topology Management</a>
<ul>
<li><a href="#overview-of-sdam-events">Overview of SDAM events</a></li>
<li><a href="#simple-code-example">Simple Code Example</a></li>
<li><a href="#example-documents-returned-for-each-event-type">Example Documents Returned For Each Event Type</a>
<ul>
<li><a href="#serverdescriptionchanged">serverDescriptionChanged</a></li>
<li><a href="#serverheartbeatstarted">serverHeartbeatStarted</a></li>
<li><a href="#serverheartbeatsucceeded">serverHeartbeatSucceeded</a></li>
<li><a href="#serverheartbeatfailed">serverHeartbeatFailed</a></li>
<li><a href="#serveropening">serverOpening</a></li>
<li><a href="#serverclosed">serverClosed</a></li>
<li><a href="#topologyopening">topologyOpening</a></li>
<li><a href="#topologyclosed">topologyClosed</a></li>
<li><a href="#topologydescriptionchanged">topologyDescriptionChanged</a></li>
</ul></li>
</ul></li>
</ul>
</nav>
  </div>
  
</div>
</div>

</div>
</div>
</div>
</section>
</section>

</section>


<script type="text/javascript">
  var DOCUMENTATION_OPTIONS = {
   URL_ROOT:    "/node-mongodb-native/3.1",
   VERSION:     "3.1",
   COLLAPSE_INDEX: false,
   FILE_SUFFIX: '.html',
   HAS_SOURCE:  true
  };
</script>
<script type="text/javascript" src="/node-mongodb-native/3.1/js/jquery.js"></script>
<script type="text/javascript" src="/node-mongodb-native/3.1/lib/bootstrap.js"></script>
<script type="text/javascript" src="/node-mongodb-native/3.1/js/navbar.js"></script>
<script type="text/javascript" src="/node-mongodb-native/3.1/lib/highlight/highlight.pack.js"></script>
<script type="text/javascript" src="/node-mongodb-native/3.1/js/scripts.js"></script>
<script type="text/javascript" src="/node-mongodb-native/3.1/lib/bootstrap-toggle/bootstrap-toggle.min.js"></script>
<script type="text/javascript" src="/node-mongodb-native/3.1/js/java.js"></script>
<script type="text/javascript" src="/node-mongodb-native/3.1/js/toggle-switch.js"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-29229787-1', 'auto');
  ga('send', 'pageview');
</script>
</body>
</html>

